<?php

namespace app\api\controller;

use think\Controller;
use think\Db;
use think\Exception;
use think\Request;

use addons\epay\library\Service;

use app\common\controller\Api;

class Goodsorder extends Api
{
//    protected $noNeedLogin = '*';

    protected $noNeedRight = ['*'];
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
    }

    public function offlinepay()
    {
        $user_id=$this->request->request('user_id');
        $id=$this->auth->id;
        model('app\common\model\User')->where('id',$id)->update(['vip_id'=>1,'isvip'=>1]);
        $data = [
                    'order_sn'=>'',
                    'user_id'=>$id,
                    'goods_id'=>1,
                    'createtime'=>time(),
                    'status'=>3,
                    ];
        model('app\admin\model\Ordermember')->insert($data);
        
        
        $recommend=model('app\common\model\User')->where('id',$user_id)->find();
        $membertype=model('app\admin\model\Membertype')->get(1);
            //有上级
            if($recommend){
                $level=Db::name('commissionlevel')->find();
                $price=$membertype['price'];
                if($recommend['level_id']==1){
                    $num=model('app\common\model\User')->where('recommend',$recommend['id'])->count();
                    if($num>10){
                        $money=$price*$level['level3']/100;
                        $memo='推广10人以上佣金';
                    }elseif ($num>2) {
                        $money=$price*$level['level2']/100;
                        $memo='推广3-10人佣金';
                    }else{
                        $money=$price*$level['level1']/100;
                        $memo='推广1-2人佣金';
                    }
                }else{
                    $money=$price*$recommend['level0']/100;
                    $memo='合作商推广佣金';
                }
                model('app\common\model\User')::money($id,$money,$recommend['id'],$memo,2);
                
                $recommend2=model('app\common\model\User')->where('id',$recommend['recommend'])->find();
                if($recommend2){
                    $money1=($price*$recommend2['level0']/100)-$money;
                    if($money1>0){
                        $memo='合作商间推佣金';
                        model('app\common\model\User')::money($id,$money1,$recommend2['id'],$memo,2);
                    }
                }
                
            }
        
    }

    /**
     * 确认订单
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function confirmOrder()
    {
//        $this->error(11);
        //        $sku_id = $this->request->request('sku_id','');
        $res = $this->request->request();
        // dump($res['goods']);exit();

<<<<<<< HEAD
        $goods=$res['goods'];
//        $goods = html_entity_decode($res['goods']);/**/

=======
        $goods=$this->request->request('goods/a',[]);
        foreach ($goods as $k=>$v){if (empty($v)) unset($goods[$k]);}
        if (empty($goods)){
            $this->error("goods参数为空!");
        }
//        $goods = html_entity_decode($res['goods']);/**/
//        $this->error($goods);
>>>>>>> 748c8aa848b0b72b0d74b176c2c74e8c68aeb612
        $isvip = $this->request->request('isvip', 1);
        if (!isset($res['goods'])) {
            $this->error('提交信息不存在');
        }
        //        $goods = $res['goods'];
//        $goods = json_decode($goods, true);
        // $goods = $res['goods'];

        //        $goods = $res['goods'];

        $goods_total = 0;

        $freight_total = 0;


        $sku_ids = array_column($goods, 'sku_id');

        $row = model('sku')->with(['goods'])->whereIn('sku.id', $sku_ids)->select();

        if (!$row) $this->error('商品不存在');
        $Goods=new Goods();
        $goods3_ids=$Goods->goodsVerification();
        if (!empty($goods3_ids)){
            $goods_ids=array_column($goods, 'goods_id');
            if (!empty(array_intersect($goods_ids, $goods3_ids))) {
                throw new Exception("已经购买过试用装商品了!");
            }
        }
        $profit_s=0;
        foreach ($row as $k => $v) {
            if ($v['stock'] < $goods[$k]['stock']) {
                $this->error('库存不足');
            }

            if ($v['goods']['status'] == 2) {
                $v['price'] = $v['money1'];
            } elseif ($isvip) {
                $v['price'] = $v['money'];
            }

            $freight = model('freight')->where('id', $v['goods']['freight_id'])->value('price');
            //
            //            $goods_total = bcadd($goods_total,$v['price'],2);
            $goods_total = bcadd($goods_total, bcmul($v['price'], $goods[$k]['stock'], 2), 2);
            $freight_total = bcadd($freight_total, $freight, 2);

            $row[$k]['stock'] = $goods[$k]['stock'];

            // $goods_id = $goods[$k]['id'];
            //
            //


            $profit=$v['price']-$v['money2'];
            $profit_s+=($profit>0)?$profit:0;
        }


        $discount = model('coupon')
            ->where('user_id', $this->auth->id)
            ->where('status', 2)
            ->where('goods_id', $goods[0]['goods_id'])
            ->value('discount') ?? 0;


        $data['goods_data'] = $row;
        $data['goods_total'] = $goods_total;
        $data['freight_total'] = $freight_total;

        $data['discount_price'] = $discount;



        $data['order_total'] = bcadd($goods_total, $freight_total, 2);

        $data['order_total'] = bcsub($data['order_total'], $discount, 2);
        $data['profit']=$profit_s;
        $this->success('success', $data);
    }


    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        $res = $this->request->request();
        if (!isset($res['goods'])) {
            $this->error('提交信息不存在');
        }
        $goods = html_entity_decode($res['goods']);
//        $this->error(11);
        $goods = json_decode($goods, true);

        $grouporder_id = $this->request->request('group_id', 0);

        $coupon_id = $res['coupon_id'] ?? 0;
        // $goods = $res['goods'];

        $coupon_id = model('coupon')
            ->where('user_id', $this->auth->id)
            ->where('status', 2)
            ->where('goods_id', $goods[0]['goods_id'])
            ->value('id') ?? 0;

        //   var_dump($coupon_id);exit();

        //        $address = model('address')
        //            ->where('id',$res['address_id'])
        //            ->where('user_id',$this->auth->id)
        //            ->find();

        //        if (!$address){
        //            $this->error('地址不存在');
        //        }

        $this->createOrder($goods, [], $grouporder_id, $coupon_id, $res);
    }

    public function createOrder($goods, $addres = '', $grouporder_id, $coupon_id = 0, $res)
    {
        $isvip =  model('user')->where('id', $this->auth->id)->value('isvip');
        $orderGoods = [];



        $goods_total = 0;
        $freight_total = 0;
        $order_total = 0;

        $order_money = 0;



        $sku_ids = array_column($goods, 'sku_id');

        $row = model('sku')->with(['goods'])->whereIn('sku.id', $sku_ids)->select();

        //        $tpye = 1;

        //         var_dump($row);exit();
        $profit=0;
        foreach ($row as $k => $v) {
            $profit+=($v['price']-$v['money2']);

            $tpye = $v['goods']['status'];
            if ($v['stock'] < $goods[$k]['stock']) {
                $this->error('库存不足');
            }

            // $address = $v['goods'];

            $freight = model('freight')->where('id', $v['goods']['freight_id'])->value('price');
            $original_price = $v['price'];
            if ($tpye == 2) {
                $v['price'] = $v['money1'];
            } elseif ($isvip) {
                $v['price'] = $v['money'];
            }
            $goods_total = bcadd($goods_total, bcmul($v['price'], $goods[$k]['stock'], 2), 2);

            $order_money = bcadd($order_money, bcmul($v['goods']['money'], $goods[$k]['stock'], 2), 2);



            $freight_total = bcadd($freight_total, $freight, 2);



            $orderGoods[] = [
                'goods_id' => $v['goods']['id'],
                'sku_id' => $v['id'],
                'sku_name' => $v['name'],
                'num' => $goods[$k]['stock'],
                'price' => $v['price'],
                'original_price' => $original_price,
                'goods_name' => $v['goods']['name'],
                'goods_image' => $v['image'],
            ];

            model('sku')->whereIn('id', $v['id'])->setDec('stock', $goods[$k]['stock']);

            model('cart')->where('user_id', $this->auth->id)->where('sku_id', $v['id'])->delete();
            //
            //

        }

        // $city = explode('/',$address['city']);

        $goodsAddress = [
            'user_id' => $this->auth->id,
            'name' => $res['stuname'],
            'phone' => $res['mobile'],
            'remark' => $res['remark'],
            'provinces' => '',
            'cities' => '',
            'districts' => '',
            'address' => '',
            'createtime' => time()
        ];


        $order_total = bcadd($freight_total, $goods_total, 2);

        $discount_price = 0;

        if ($coupon_id) {

            $discount = $discount_price = model('Coupon')->where('user_id', $this->auth->id)
                ->where('status', 2)
                ->where('id', $coupon_id)
                ->value('discount');
            if (!$discount) {
                $this->error('优惠券不存在');
            }

            if ($discount > 0) {
                $order_total  = bcsub($order_total, $discount, 2);
            }
        }

        if ($discount_price > 0) {

            $order_money = bcsub($order_money, $discount_price);
        }





        $order = [
            'order_sn' => 'OD' . time() . rand(100, 999) . $this->auth->id,
            //            'pay_sn'=>'PS'.time().rand(100,999).$this->auth->id,
            'user_id' => $this->auth->id,
            'goods_total' => $goods_total,
            'grouporder_id' => $grouporder_id,
            'freight_total' => $freight_total,
            'order_total' => $order_total,
            'pay_total' => $order_total,
            'coupon_id' => $coupon_id,
            'order_money' => $order_money,
            'discount_price' => $discount_price,
            'tpye'  => $tpye,
            'createtime' => time(),
            'profit'=>$profit
        ];
        $order_id = 0;
        Db::startTrans();
        try {
            $order_id = model('order')->insertGetId($order);

            $goodsAddress['order_id'] = $order_id;
            $arr = ['order_id' => $order_id];
            array_walk($orderGoods, function (&$value, $key, $arr) {
                $value = array_merge($value, $arr);
            }, $arr);


            $bool2 = model('app\common\model\order\Address')->insert($goodsAddress);
            $bool = model('app\common\model\order\Goods')->insertAll($orderGoods);

            if ($coupon_id > 0) {
                model('Coupon')->where('id', $coupon_id)->update(['status' => 3]);
            }

            if ($order_id && $bool && $bool2) {
                Db::commit();
            } else {

                Db::rollback();
                $this->error('生成失败');
            }
        } catch (\Exception $e) {
            Db::rollback();
            $this->error('生成失败');
        }


        //        if ($tpye == 2){


        //            $user = $this->auth->getUserinfo();
        //
        //
        //            $pay_password = $this->request->request('pay_password','');

        // if(!$pay_password){ 
        //     $this->error('请输入支付密码');
        // }

        // if ($user['pay_password'] != md5($pay_password)) {
        //     $this->error('密码不正确');
        // }

        //            if ($user['money'] < $order['pay_total']){
        //                $this->error('欢乐果不足');
        //            }
        //            model('user')::money(-$order['pay_total'],$user['id'],'商品兑换');
        //            model('order')->backOrder($order['order_sn']);

        //            $this->success('兑换成功');
        //        }

        //购物车清空


        $this->success('生成成功', [
            'order_sn' => $order['order_sn'],
            'order_id' => $order_id,
            'pay_total' => $order_total
        ]);
    }


    public function paylist()
    {
        $list = model('paygoods')->select();

        $this->success('success', $list);
    }

//确认支付
    public function payOrder()
    {
        $order_id = $this->request->request('order_id', 0);
        $pay_id = $this->request->request('pay_id', '');
        $pay_image = $this->request->request('pay_image', '');

        $pay_type = $this->request->request('pay_type', 'h5');

        $order = model('order')
            ->where('id', $order_id)
            ->where('user_id', $this->auth->id)
            ->where('status', 1)
            ->find();

        if (!$order) $this->error('订单不存在');

        if ($order['tpye'] == 3) {
            $goods_id = model('app\common\model\order\Goods')
                ->where('order_id', $order['id'])
                ->value('goods_id');
            $goodsOrder = model('goods')->where('goods.id', $goods_id)->with(['seckill'])->find();

            //            if ($goodsOrder['status'] == 3){
            //                if ($goodsOrder['seckill']['times'] > date('H:m')
            //                    || $goodsOrder['seckill']['endtime'] < date('H:m')
            //                ){
            //                    $this->error('秒杀已结束');
            //                }
            //            }
        }



        if (!$pay_id) $this->error('请选择付款方式');

        $pay = model('paygoods')->where('id', $pay_id)->find();

        if ($pay['state'] == 1 && !$pay_image) $this->error('请上传付款截图');

        if ($pay['state'] == 1) {
            $order->pay_id = $pay_id;
            $order->pay_image = $pay_image;
            $order->status = 6;
            $order->paytime = time();
            $order->save();
            $this->success('success', ['status' => 1]);
        }

        if ($pay['code'] == 'wechat' && $pay['state'] == 2) {

            $serviceModel = new Service();

            // $openid = model('app\common\model\User')->where('id',$this->auth->id)->value('openid');
            //            $returnurl = 'https://gyt.henanguoyitang.asia/#/pages/order/order';


            $openid = '';
            if ($pay_type != 'h5') {
                $openid = $this->request->request('openid', '');
                $method = 'mp';
            } else {
                $method = 'wap';
            }
            $openid = model('app\common\model\User')->where('id', $this->auth->id)->value('openid');


            $order->pay_id = $pay_id;
            $order->save();

            $request = request();

            $notifyurl = $request->root(true) . '/addons/epay/index/notifyxgoods/paytype/wechat';

            $response = $serviceModel::submitOrder(
                $order->pay_total,
                $order->order_sn,
                'wechat',
                '用户购买',
                $notifyurl,
                $notifyurl,
                'miniapp',
                $openid
            );



            // return $response;
            // var_dump($response);exit();

            // $response['money'] = -$order['pay_price'];
            // $response['paydate'] = date('Y-m-d',time());
            // $response['paystatus'] = $order['goods_name'];


            //上级返利pay_total
            $profit_price=$order['profit'];
            $User=new \app\common\model\User();
            $user=$this->auth->getUser();
            $recommend=model('app\admin\model\User')
                ->where('id',$user['recommend'])
                ->find();
            if (empty($user['my_level']) || $user['my_level']==0) {
                if (!empty($user['recommend'])){
                    if (empty($recommend)){
                        //没有上级
                    }else{
                        switch ($recommend['my_level']){
                            case '1':
                                $profit=$profit_price*0.2;//%
                                $User::money(0,$profit,$recommend['id'],"获取了下级$user[id]=>$user[nickname]的直接返利$profit!");
                                if (!empty($recommend['my_level'])){
                                    $recommend2=model('app\admin\model\User')
                                        ->where('id',$recommend['my_level'])
                                        ->find();
                                    if (empty($recommend2) || $recommend2['my_level']!=2){
                                        //丢失上级
                                    }
                                    $total_profit=$profit_price*0.05;//%
                                    $User::money(0,$total_profit,$recommend2['id'],"获取了下级$recommend[id]=>$user[nickname]的间接返利$total_profit!");
                                }
                                break;
                            case '2':
                                $profit=$profit_price*0.25;//%
                                $User::money(0,$profit,$recommend['id'],"获取了下级$user[id]=>$user[nickname]的直接返利$profit!");
                                break;
                        }
                    }
                }
            }elseif($user['my_level']==1){
                if (empty($recommend)){
                    //没有上级
                }else{
                    switch ($recommend['my_level']){
                        case '1':
                            break;
                        case '2':
                            $profit=$profit_price*0.25;//%
                            $User::money(0,$profit,$recommend['id'],"获取了下级$user[id]=>$user[nickname]的直接返利$profit!");
                            break;
                    }
                }
            }





            $this->success('成功', $response);
        }
    }







    public function payOrder1()
    {
        $price = $this->request->request('price');
        $id= $this->request->request('id');
        $order_sn='OD'.time().$this->auth->id.rand(10,99);
        $serviceModel = new Service();
        $method = 'mp';
        $openid = model('app\common\model\User')->where('id', $this->auth->id)->value('openid');
        $request = request();
        $notifyurl = $request->root(true) . '/addons/epay/index/notifyxgoods1/paytype/wechat';
        $response = $serviceModel::submitOrder(
            $price,
            $order_sn,
            'wechat',
            '开通会员',
            $notifyurl,
            $notifyurl,
            'miniapp',
            $openid
        );
        $data = [
            'order_sn'=>$order_sn,
            'user_id'=>$this->auth->id,
            'goods_id'=>$id,
            'createtime'=>time()
        ];
        model('app\admin\model\Ordermember')->insert($data);
        $this->success('成功', $response);
        
    }


    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
    
    public function orderList1()
    {
        $course=$this->request->request('course');
        if($course){
            $list=Db::name('goods')
            ->whereNotIn('id',[14,15,32])
            ->paginate();
            // $list = model('order')
            // ->with(['ordergoods'])
            // ->where('user_id', $this->auth->id)
            // ->where('status','exp', '= 3 or status = 4')
            // ->group('user_id')
            // ->order('status asc, paytime desc,createtime desc')
            // ->paginate();
            $this->success('success', $list);
        }
        $type = $this->request->request('type', 1);
        $status = $this->request->request('status', '');

        $model = model('order')
            ->with(['ordergoods'])
            ->where('user_id', $this->auth->id)
            ->where('is_del', 1)
            ->where('tpye', $type);

        if ($status) {
            $model->where('status', $status);
        }

        $list = $model->order('status asc, paytime desc,createtime desc')->paginate();

        $this->success('success', $list);
    }
    
    public function orderList()
    {
        $course=$this->request->request('course');
        if($course){
            $list=Db::name('order_goods')->alias('g')->join('order o','g.order_id=o.id')->where('o.user_id', $this->auth->id)
            ->where('o.status','exp', '= 3 or status = 4')
            ->group('goods_id')
            
            ->paginate();
            // $list = model('order')
            // ->with(['ordergoods'])
            // ->where('user_id', $this->auth->id)
            // ->where('status','exp', '= 3 or status = 4')
            // ->group('user_id')
            // ->order('status asc, paytime desc,createtime desc')
            // ->paginate();
            $this->success('success', $list);
        }
        $type = $this->request->request('type', 1);
        $status = $this->request->request('status', '');

        $model = model('order')
            ->with(['ordergoods'])
            ->where('user_id', $this->auth->id)
            ->where('is_del', 1)
            ->where('tpye', $type);

        if ($status) {
            $model->where('status', $status);
        }

        $list = $model->order('status asc, paytime desc,createtime desc')->paginate();

        $this->success('success', $list);
    }

    public function orderDetails1()
    {
        // $list = model('app\admin\model\Video')->select();
        
        // foreach ($list as $k => $v) {
        //     model('app\admin\model\Video')->where('id', $v['id'])->update(['weigh' => $v['id']]);
        // }
        // print_r($list);
        // die;
        $id = $this->request->request('id');
        $row = model('app\admin\model\Video')
            ->where('status', 1)
            ->where('goods_id', $id)
            ->order('weigh asc')
            ->select();
        $this->success('success', $row);
    }
    public function orderDetails()
    {
        $id = $this->request->request('id', 0);
        $row = model('order')
            ->with(['ordergoods', 'company'])
            ->where('order.id', $id)
            ->where('user_id', $this->auth->id)
            ->find();


        $grouporder_id = model('app\common\model\Groupuser')
            ->where('order_id', $id)
            ->where('user_id', $this->auth->id)
            ->value('grouporder_id');
        $row['grouptime'] = '';
        if ($grouporder_id) {

            $createtime = model('app\common\model\Grouporder')
                ->where('id', $grouporder_id)
                ->value('createtime');
            $row['grouptime'] = date('Y-m-d H:i:s', $createtime);
        }




        $row['address'] = model('app\common\model\order\Address')
            ->where('order_id', $row['id'])
            ->find();

        $this->success('success', $row);
    }

    public function confirmTake($id=null,$return=false)
    {
        $id =empty($id)? $this->request->request('id', 0):$id;
        if (empty($id)){
            $this->error("id参数不足!");
        }
        $row = model('order')
            ->with(['grouporder'])
            ->where('id', $id)
            ->where('status', 3)
            ->where('user_id', $this->auth->id)
            ->find();
        if (!$row) $this->error('订单不存在');
        $row->status = 4;
        $row->taketime = time();
        $row->save();

        //拼团订单团长收货团员自动收货
        if ($row['tpye']==2 || $row['user_id']==$row['grouporder']['user_id']){
            $orders=model('order')
                ->where('grouporder_id',$row['grouporder_id'])
//                ->where('')
                ->select();
            foreach ($orders as $k=>$v){
                $this->confirmTake($v['id'],true);
            }
        }

        if ($return){
            return true;
        }
        $this->success('收货成功');
    }


    public function delOrder()
    {

        $id = $this->request->request('id', 0);
        $row = model('order')
            ->where('id', $id)
            // ->where('status',5)
            ->where('user_id', $this->auth->id)
            ->find();
        if (!$row) $this->error('订单不存在');
        $row->is_del = 2;
        $row->deltime = time();
        $row->save();
        $this->success('删除成功');
    }

    public function commentAdd()
    {
        $id = $this->request->request('id', 0);

        $goodsorder_id = $this->request->request('goodsorder_id', 0);

        $name = $this->request->request('name', '');
        $images = $this->request->request('images', '');

        if (!$name) $this->error('请输入评论内容');
        //        if (!$images) $this->error('请上传图片');


        $row = model('order')
            ->where('id', $id)
            ->where('status', 4)
            ->where('user_id', $this->auth->id)
            ->find();

        // var_dump($id);exit();



        if (!$row) $this->error('订单不存在');




        if ($row['comment_id'] > 0) $this->error('已全部评论');


        $orderGoods = model('app\common\model\order\Goods')->where('id', $goodsorder_id)->where('comment_id', 0)->find();


        if (!$orderGoods) {
            $this->error('此商品已无法评论');
        }


        $bool = model('comment')->insertGetId([
            'user_id' => $this->auth->id,
            'order_id' => $id,
            'goods_id' => $orderGoods['goods_id'],
            'name'    => $name,
            'images' => $images,
            'createtime' => time()
        ]);
        $orderGoods->comment_id = $bool;
        $orderGoods->save();

        if (model('app\common\model\order\Goods')->where('order_id', $id)->where('comment_id', 0)->count() == 0) {
            $row->comment_id = 1;
            $row->save();
        }
        // $row->save();

        $bool ? $this->success('success') : $this->error('提交失败');
    }


    public function orderGoods()
    {

        $id = $this->request->request('id', 0);


        $row = model('order')
            ->where('id', $id)
            ->where('status', 4)
            // ->where('user_id',$this->auth->id)
            ->find();

        if (!$row) $this->error('订单不存在');


        $list = model('app\common\model\order\Goods')->where('order_id', $id)->select();
        $this->success('success', $list);
    }

    //取消订单
    public function cancelOrder()
    {

        $id = $this->request->request('id', 0);

        $row = model('order')
            ->where('id', $id)
            ->where('status', 1)
            ->where('user_id', $this->auth->id)
            ->find();

        if (!$row) $this->error('订单不存在');

        $row->status = 5;

        $row->canceltime  = time();

        $row->save();

        $this->success('success');
    }


    public function groupOrderDetails()
    {
        $id = $this->request->request('id', 0);

        $row = model('order')
            ->with(['ordergoods'])
            ->where('id', $id)
            //            ->where('status',1)
            ->where('user_id', $this->auth->id)
            ->find();

        // var_dump($row['ordergoods'][0]->goods_id);exit();

        // $row['ordergoods'][0]->original_price = model('goods')->where('id',$row['ordergoods'][0]->goods_id)->value('price');

        $grouporder_id = model('app\common\model\Groupuser')
            ->where('order_id', $id)
            ->where('user_id', $this->auth->id)
            ->value('grouporder_id');

        $Grouporder = model('app\common\model\Grouporder')
            ->where('id', $grouporder_id)
            ->find();



        $groupuser = model('groupuser')->with(['user'])
            ->where('grouporder_id', $grouporder_id)
            //                ->where('type',1)
            ->select();


        $Grouporder['groupuser'] = $groupuser;

        $row['grouporder'] = $Grouporder;
        //        dump($UserGroup);exit();

        $this->success('success', $row);
        //        order_id

    }
}
